//
//  ZYZBaseController.swift
//  MyWeiBo
//
//  Created by 牛牛很牛 on 15/12/15.
//  Copyright © 2015年 曾勇召. All rights reserved.
//

import UIKit

class ZYZBaseController: UITableViewController, ZYZVisitorViewDelegate {
  
    //判断用户是否登录
    var userLogin = ZYZUserAcount.userLogin
    override func loadView() {
        userLogin ? super.loadView() : self.setupVistorView()
    }
    
    func setupVistorView(){
        view = visitorView
        
        
        //先设置协议，再指定代理
        visitorView.delegate = self
        
        //根据不同控制器其设置不同内容
        if self is ZYZHomeController{
            visitorView.startRotateAnimation()
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground", name: UIApplicationDidEnterBackgroundNotification, object: nil)
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didBecomeActive", name: UIApplicationDidBecomeActiveNotification, object: nil)
        }
        else if self is ZYZMessageController{
            visitorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        }else if self is ZYZDiscoveryController{
            visitorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }else if self is  ZYZProfileController{
            visitorView.setupVisitorInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        
        //设置导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewRegisterClick")
          navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewLoginClick")
        
       
        
    }
    
    func visitorViewLoginClick() {
        let aouthVC = ZYOauthController()
        self.presentViewController(UINavigationController(rootViewController: aouthVC), animated: true) { (_) -> Void in
        }
    }
    
    func visitorViewRegisterClick() {
        //跳转其他控制器
    }
    
    
    
    //监听通知
    func didEnterBackground(){
    visitorView.pauseAnimation()
    }
    func didBecomeActive(){
    visitorView.resumeAnimation()
    }
    
    //懒加载
    lazy var visitorView :ZYZVisitorView = ZYZVisitorView()
}


//实现代理
//extension ZYZBaseController : ZYZVisitorViewDelegate{
//    func visitorViewRegisterClick(){
//    }
//    func visitorViewLoginClick(){
//    }
//    
//}